#include <boost/algorithm/string.hpp>
#include "Attachment.h"
#include "../../smtp/data/SMTPDefaults.h"

using namespace kc_sf;
namespace ba = boost::algorithm;

// ----------------------------------------------------------- //

Attachment::Attachment(const std::string &text, const ContentType &ct)
: a_content_type (ct),
  a_body(text, _8Bit, ASCII)
{
}

Attachment::Attachment( const std::string &text,
            EncodingType encoding,
            const std::string &charset,
            const ContentType &ct)
: a_content_type (ct),
  a_body (text, encoding, charset)
{
}

Attachment * Attachment::clone() const
{
	return new Attachment (*this);
}

// ----------------------------------------------------------- //

const UnicodeString & Attachment::getDecodedText()
{
	return a_body.getDecodedText();
}

const std::string & Attachment::getOriginalText() const
{
	return a_body.getOriginalText();
}

unsigned long Attachment::getSize() const
{
	return a_body.getSize();
}

std::string Attachment::getFilename() const
{
	return boost::trim_copy( aFilename );
}

std::string Attachment::getExtension() const
{
	std::string ext = "";
	std::string name = aFilename;

	size_t dot = name.find_last_of('.');
	if (dot != std::string::npos)
	{
		size_t size = name.size() - dot - 1;
		ext = name.substr(dot + 1, size);
		boost::trim( ext );
	}

	return ext;
}
